Dashboard Temp Share Shortlinks Frames API

HTMLify

Largest Odd Number in String.cpp
Views: 1 | Author: cody
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
class Solution {
public:
    string largestOddNumber(string num) {
        int n = num.length();
        string ans = "";
        for(int i =n-1; i>=0; i--){
           if(num[i] %2 !=0){
               return num.substr(0, i+1);
           }
        }
        return "";
        
    }
};